﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using My.Admin.Service.System;
using My.Core.Constant;
using My.Core.CustomException;
using My.Core.Enums;
using StackExchange.Profiling;

namespace My.Admin.Controllers
{
    /// <summary>
    /// 授权管理示例
    /// </summary>
    [ApiController]
	[Route("[controller]")]
	public class TestController : ControllerBase
	{
		private readonly OtherService testClass;

		public TestController(OtherService test)
		{
			testClass = test;
		}

		[HttpGet]
		[Authorize(Permissions.UserUpdate)]
		public string Get()
		{
			return testClass.Test().ToString();
			
		}


		[Route("Test123")] // 路由地址规则
		[HttpGet]
		[Authorize]
		public string Test123(int i)
		{
			CustomException customException = new CustomException(ResultCode.CUSTOM_ERROR, "自定义异常", "自定义异常测试");
			throw customException;
			return testClass.Test().ToString();
		}


		[Route("Test12")] // 路由地址规则
		[HttpGet]
		public string Test12(int i,int j)
		{
			return testClass.Test().ToString();
		}

		/// <summary>
		/// 获取MiniProfiler的html片段
		/// </summary>
		/// <returns></returns>
		[HttpGet]
		[Route("GetHtml")]
		public IActionResult GetHtml()
		{
			var html = MiniProfiler.Current.RenderIncludes(HttpContext);
			return Ok(html.Value);
		}
	}
}
